﻿using System;
using System.Collections.Generic;
using System.Web.Http.Filters;

namespace Odn.WebApi.Filters
{
    public class ApiExceptionHandlerFilterAttribute : ExceptionFilterAttribute
    {
        private Dictionary<Type, Type> exceptionToHandlerMapping = new Dictionary<Type, Type>();

        public ApiExceptionHandlerFilterAttribute()
        {
            //var types = IocManager.Instance.Resolve<ITypeFinder>().Find(x => { return typeof(IApiExceptionHandler).IsAssignableFrom(x) && !x.IsAbstract; });

            //foreach (var handlerType in types)
            //{
            //    var attribute = handlerType.GetCustomAttribute<HandleException>(true);
            //    if (attribute != null)
            //        exceptionToHandlerMapping.Add(attribute.ExceptionType, handlerType);
            //    else if (!(handlerType == typeof(DefaultExceptionHandler)))
            //    {
            //        logger.WarnFormat("Type {0} is a ApiExceptionHandler but not specify the specific error type");
            //    }
            //}
        }

        public override void OnException(HttpActionExecutedContext context)
        {
            //var apiTypeAttribute = context.ActionContext.ActionDescriptor.ControllerDescriptor.GetCustomAttributes<ApiTypeAttribute>().SingleOrDefault();
            //if (apiTypeAttribute != null && apiTypeAttribute.ApiType == ApiTypeEnum.平台)
            //{
            //    PlatformErrorHandler(context);
            //}
            //else
            //{
            //    InternalErrorHandler(context);
            //}
        }
    }
}
